extends Control

signal success_game() #定义信号 开始游戏

@onready var timer = $Timer

var extraMoneyByFunctionCard = 0 #功能牌获得的金

var root

func _ready() -> void:
	root = self.get_parent()

#结算金币
func changeMoney():
	self.visible = true
	timer.start() #启动计时器
	await timer.timeout # 等待
	#展示当前持有money
	$CurrentMoney.text = "当前:" + str(PlayerDetail.playerMoney)
	timer.start() #启动计时器
	await timer.timeout # 等待
	# 1.上回合利息，每5金币，得1利息
	var interest = PlayerDetail.playerMoney / 5
	$InterestMoney.text = "利息:" + str(interest)
	timer.start() #启动计时器
	await timer.timeout # 等待
	# 2.
	#2.1剩余出牌次数 = 要加的金币数
	#2.2赢得小回合 +2 赢得庄 +4
	var winMoney = root.nocp
	if RoundDetail.currentSmallRound != 5:
		winMoney += 2
	else:
		winMoney += 4
	$WinMoney.text = "赢得:" + str(winMoney)
	timer.start() #启动计时器
	await timer.timeout # 等待
	# 3.看看是否有功能牌额外添加的金币
	var extraMoney = extraMoneyByFunctionCard
	$ExtraMoney.text = "额外:" + str(extraMoney)
	timer.start() #启动计时器
	await timer.timeout # 等待
	# 4.最终金币
	PlayerDetail.playerMoney = PlayerDetail.playerMoney + interest + winMoney + extraMoney
	$FinalMoney.text = "最终:" + str(PlayerDetail.playerMoney)
	timer.start() #启动计时器
	await timer.timeout # 等待
	
	$NextRound.visible = true
	

# 点击下一回合事件
func _on_next_round_pressed() -> void:
	$ClickAudio.play()
	emit_signal("success_game")  # 发送信号 下一回合
